package edu.xy.hm02_01.slice;

import edu.xy.hm02_01.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;
import ohos.agp.components.DirectionalLayout;
import ohos.agp.components.Image;

public class MainAbilitySlice_05 extends AbilitySlice {
    Image image=null;
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        // 设置该页面所关联的页面布局
        super.setUIContent(ResourceTable.Layout_ability_main_05);
        
        //  获取整个屏幕对象和图片对象
        DirectionalLayout layout = (DirectionalLayout)this.findComponentById(ResourceTable.Id_layout_05);
        image = (Image)this.findComponentById(ResourceTable.Id_image_05_01);

        layout.setDoubleClickedListener(this::doubleClickedListenerLayout);

        image.setClickedListener(this::clickedListenerImage);

    }

    private void clickedListenerImage(Component component) {
        // 修改图片组件的图片源
        image.setImageAndDecodeBounds(ResourceTable.Media_white);
    }

    private void doubleClickedListenerLayout(Component component) {

        image.setImageAndDecodeBounds(ResourceTable.Media_red);
    }


    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
